package com.sec.android.app.myfiles.launch;

import android.app.Activity;
import android.app.DownloadManager;
import android.content.Intent;

import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.info.AppConstants.StoragePath;
import com.sec.android.app.myfiles.log.SamsungAnalyticsLog;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.module.abstraction.FileRecord.StorageType;
import com.sec.android.app.myfiles.navigation.NavigationInfo;
import com.sec.android.app.myfiles.navigation.NavigationInfo.NavigationMode;
import com.sec.android.app.myfiles.navigation.NavigationManager;

public class HandleDownloadHistoryImp extends AbsHandleLaunchImp {

    @Override
    public boolean isMyJob(Intent intent) {
        final String action = intent.getAction();
        return DownloadManager.ACTION_VIEW_DOWNLOADS.equals(action);
    }

    @Override
    public boolean _handleStart(int processId, Activity activity, Intent intent) {
        NavigationManager navigationMgr = NavigationManager.getInstance(processId);
        FileRecord record;
        if (intent != null && intent.getBooleanExtra(AppConstants.INTENT_FROM_SAMSUNG_INTERNET, false)) {
            record = FileRecord.createFileRecord(StorageType.Downloads, StoragePath.DOWNLOAD_HISTORY);
        } else {
            record = FileRecord.createFileRecord(StorageType.Downloads, StoragePath.DOWNLOAD_HISTORY_FROM_OTHERS);
        }
        NavigationInfo info = NavigationInfo.getInstance(NavigationMode.Normal, record);
        info.setScreenPath(SamsungAnalyticsLog.ScreenPath.FROM_INTERNET);
        navigationMgr.enterWithClean(info);
        return true;
    }
}
